<?php
/**
 * Display a table with three colunm table caption is 'Unit Selection'
 * each cell will consist of a unit descrition, unit image and unit status
 */
$units=array_chunk($cdeUnits,3);
?>
	<h2>Unit selection</h2>
	<table class="unitSelection">
	<?php
	foreach ($units as $cdeUnit) {
	?>
		<tr>
		<?php
		foreach ($cdeUnit as $unitValue) {
			//if file does not exist, default image will be displayed
			$image=$unitValue['CdeUnit']['imageurl'];
		?>
			<td>
				<table class="unit">
					<tr>
						<td class="unitTitle"><a href="../cde_units/unitintro/<?php echo $unitValue['CdeUnit']['id']; ?>"><?php echo $unitValue['CdeUnit']['title']; ?></a></td>
					</tr>
					<tr>
						<td class="unitImage"><a href="../cde_units/unitintro/<?php echo $unitValue['CdeUnit']['id']; ?>"><img src="<?php echo $image; ?>" width=200 height=180 onerror="this.src='../img/default.jpg'"/></a></td>
					</tr>
					<tr>
						<?php
							if ($unitValue['CdeUnit']['status']=="Completed") {
								echo "<td class='unitCompleted'>".$unitValue['CdeUnit']['status']."</td>";
							} else if (($unitValue['CdeUnit']['status']=="Uncompleted")) {
								echo "<td class='unitUncompleted'>".$unitValue['CdeUnit']['status']."</td>";
							} else {
								echo "<td class='unitNew'>".$unitValue['CdeUnit']['status']."</td>";
							}
						?>
					</tr>
				</table>
			</td>
		<?php
		}
		?>
	</tr>
	<?php
	}
	?>
</table>
